home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 3
/
Info_Mac_1994-01.iso
/
Development
/
Information
/
PowerModule Development Info
/
SpeakPhrase ƒ
/
SpeakPhrase.c
< prev
next >
Wrap
Text File
|
1993-10-08
|
3KB
|
107 lines
////////////////////////////////////////////////////////////////////////////////////////////////
//
// SpeakPhrase.c
//
// This is a PowerModule that simply speaks the string in a STR# resource. This is a *very*
// simple example of how to write a PowerModule. The code resource that is generated from
// this stuff must be of type 'PMod' and be merged into a file of type 'PMod' whose creator
// is of type 'PBin'.
//
// ©1993 Scott A. Johnson
//
///////////////////////////////////////////////////////////////////////////////////////////////
#include <GestaltEqu.h>
#include <Processes.h>
#include <Speech.h>
// These are the 4 possible messages that PowerBar can send us
#define kInitModule 0
#define kPerformAction 1
#define kDoAbout 2
#define kNoFiles 3
// Misc. alerts
#define kAboutSpeakPhrase 128
#define kNeedSpeechManager 129
// resource defines
#define kMessageStringID 128
#define kIndex2OurMsg 1
/* This is the main entry point for a PowerModule. It is much like writing 'xDEF' type
code resources. The message parameter tells us what we need to do. The finderPSN
parameter is the process serial number of the Finder if we need it. The wantFiles
parameter can be sent during the kInitModule processing to tell PowerBar to send an
array of FSSpec records our way. The wantAliases parameter indicates that, if NOT
set, PowerBar should attempt to resolve aliases before passing them to us. The
numFiles parameter will be the number of file specs passed in the next parameter,
files. This is only so, of course, if we requested the file list in the first place. */
pascal OSErr main (
short message, // what do do
ProcessSerialNumber *finderPSN, // Finder's process
Boolean *wantFiles, // do we want to use files?
Boolean *wantAliases, // do we want aliases if available
short numFiles, // how many files to process
FSSpecArrayPtr files ) // the files demselves
{
Str255 phrase;
long speechAttrib;
OSErr err=noErr;
switch( message ) {
case kInitModule:
/* Do any initial processing. In our case, we need to make sure
the Speech Manager is present before we can proceed. */
err = Gestalt( gestaltSpeechAttr, &speechAttrib );
if( err || !( speechAttrib & 0x01 ) ) {
// OOPS! Speech Manager not available. Tell the user.
(void)Alert( kNeedSpeechManager, NULL );
err = (OSErr)1;
} else {
*wantFiles = FALSE; // don't want files or aliases
*wantAliases = FALSE;
}
break;
case kPerformAction:
/* This message is sent to us to actually do what we are here to do.
Note that our resource file is made "current" before we're called. */
GetIndString( phrase, kMessageStringID, kIndex2OurMsg );
if( phrase[0] > 0 ) {
SpeakString( ( StringPtr )phrase );
while( SpeechBusy() ) ; // don't leave before we're done!
}
break;
case kDoAbout:
/* This message is sent to us if the user pressed the COMMAND key
while clicking our button. We should tell 'em about ourself :) */
(void)Alert( kAboutSpeakPhrase, NULL );
break;
case kNoFiles:
/* This message will be sent to us when we requested files, but none
were available. That is, the user clicked us but didn't select any
files before doing so! Not appropriate in our case. */
break;
}
return( err );
}